package com.base.service.impl;

import java.util.List;

import com.base.bean.Cardstuff;
import com.base.service.CardstuffService;
import com.common.util.AbstractManager;
import com.common.util.PagerModel;

public class CardstuffServiceImpl extends AbstractManager implements
		CardstuffService {

	public void addCardstuff(Cardstuff cardstuff) {
		String hql = "select nvl(max(stuffno),0) from Cardstuff";
		
		long stuffno = 0l;
		stuffno = (Long) this.getHibernateTemplate().find(hql).get(0);
		stuffno += 1l;
		
		cardstuff.setStuffno(stuffno);
		this.getHibernateTemplate().save(cardstuff);
	}

	@SuppressWarnings("unchecked")
	public List<Cardstuff> findAllCardstuff() {
		String hql = "from Cardstuff order by stuffno";
		return this.getHibernateTemplate().find(hql);
	}

	public Cardstuff findCardstuff(long stuffno) {
		return (Cardstuff) this.getHibernateTemplate().load(Cardstuff.class, stuffno);
	}

	public PagerModel findCardstuffForPager() {
		String hql = "from Cardstuff order by stuffno";
		return searchPaginated(hql);
	}

	public void removeCardstuff(long stuffno) {
		Cardstuff cardstuff = null;
		cardstuff = (Cardstuff) this.getHibernateTemplate().load(Cardstuff.class, stuffno);
		if(cardstuff != null) 
			this.getHibernateTemplate().delete(cardstuff);
	}

	public void updateCardstuff(Cardstuff cardstuff) {
		this.getHibernateTemplate().update(cardstuff);
	}

}
